import axios from "axios";

let baseUrl = "http://localhost:8082/api";
// export const instance = axios.create({
//   baseURL: baseUrl,
//   responseType: "json"
// });
axios.defaults.baseURL = baseUrl;

axios.interceptors.response.use(
  response => {
    if (response.data.status === 200) {
      return Promise.reject(response.data.message);
    }
    console.log(response);
    return response;
  },
  error => {
    console.log("错误信息", error);
    return Promise.reject(error);
  }
);

export const fetch = (url, params) => {
  return new Promise((resolve, reject) => {
    axios
      .post(url, params)
      .then(
        response => {
          resolve(response.data);
        },
        err => {
          reject(err);
        }
      )
      .catch(error => {
        reject(error);
      });
  });
};
